using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class EmojiListCtrl : UserControl
	{
		private const string TAG = "EmojiListCtrl";
		private const int ListView = 0;
		private const int EmptyInfoView = 1;
		public static DateTime lastClickTime = DateTime.get_Now().AddDays(-1.0);
		private EmojiSelectComplete mEmojiSelectComplete;
		private List<EmojiArt> currentEmojiArtList;
		private int currentLoadedArtIndex;
		internal Grid LayoutRoot;
		internal TextBlock PageTitle;
		internal ViewFlipper emojiFliper;
		internal ScrollViewer mScrollViewer;
		internal StackPanel EmojiList;
		private bool _contentLoaded;
		public EmojiListCtrl()
		{
			base.set_Visibility(1);
			this.InitializeComponent();
		}
		public static bool IsNeedResponse()
		{
			if (EmojiListCtrl.lastClickTime > DateTime.get_Now().AddSeconds(-2.0) && EmojiListCtrl.lastClickTime < DateTime.get_Now())
			{
				Log.smethod_5("EmojiListCtrl", "IsNeedResponse is false");
				return false;
			}
			return true;
		}
		public void SelectCustomEmoji(ChatPageCtrl originPage, EmojiSelectComplete emojiSelectComplete, EmojiArtGroup group)
		{
			this.mEmojiSelectComplete = emojiSelectComplete;
			this.mScrollViewer.ScrollToVerticalOffset(0.0);
			this.InitEmojiList(group);
			base.set_Visibility(0);
		}
		public void SelectCustomEmoji(SendMessagePage originPage, EmojiSelectComplete emojiSelectComplete, EmojiArtGroup group)
		{
			this.mEmojiSelectComplete = emojiSelectComplete;
			this.mScrollViewer.ScrollToVerticalOffset(0.0);
			this.InitEmojiList(group);
			base.set_Visibility(0);
		}
		private void newItem_Loaded(object sender, RoutedEventArgs e)
		{
		}
		public void DoLoad()
		{
			if (this.currentEmojiArtList == null || this.currentEmojiArtList.get_Count() <= 0)
			{
				return;
			}
			if (this.currentLoadedArtIndex < 0 || this.currentLoadedArtIndex >= this.currentEmojiArtList.get_Count())
			{
				return;
			}
			EmojiArt emojiArt = this.currentEmojiArtList.get_Item(this.currentLoadedArtIndex);
			if (emojiArt == null)
			{
				return;
			}
			EmojiItem emojiItem = new EmojiItem();
			emojiItem.InitData(emojiArt, new RoutedEventHandler(this.OnItemDelete));
			emojiItem.add_Loaded(new RoutedEventHandler(this.newItem_Loaded));
			emojiItem.add_Click(new RoutedEventHandler(this.newItem_Click));
			this.EmojiList.get_Children().Add(emojiItem);
			this.currentLoadedArtIndex++;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.DoLoad();
			});
		}
		public void RefreshEmptyInfo()
		{
			if (this.EmojiList.get_Children() != null && this.EmojiList.get_Children().get_Count() > 0)
			{
				this.emojiFliper.ShowView(0);
				return;
			}
			this.emojiFliper.ShowView(1);
		}
		public void OnItemDelete(object sender, RoutedEventArgs e)
		{
			EmojiItem emojiItem = sender as EmojiItem;
			if (emojiItem == null)
			{
				return;
			}
			EmojiArt mEmojiArt = emojiItem.mEmojiArt;
			if (mEmojiArt == null)
			{
				return;
			}
			using (IEnumerator<UIElement> enumerator = this.EmojiList.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					UIElement current = enumerator.get_Current();
					EmojiItem emojiItem2 = current as EmojiItem;
					if (emojiItem2 != null && emojiItem2 == emojiItem)
					{
						this.EmojiList.get_Children().Remove(emojiItem2);
						StorageMgr.emojiArt.method_4(mEmojiArt);
						break;
					}
				}
			}
		}
		public void InitEmojiList(EmojiArtGroup group)
		{
			this.EmojiList.get_Children().Clear();
			if (group == null)
			{
				return;
			}
			if (R.isChineseTW())
			{
				this.PageTitle.set_Text(group.strPackName_zh_tw);
			}
			else
			{
				if (R.isChineseCN())
				{
					this.PageTitle.set_Text(group.strPackName_zh_cn);
				}
				else
				{
					this.PageTitle.set_Text(group.strPackName_en_us);
				}
			}
			List<EmojiArt> list = EmojiManager.getList(group.nPackID, group.nPackID == 1);
			if (list != null && list.get_Count() > 0)
			{
				this.currentEmojiArtList = list;
				this.currentLoadedArtIndex = 0;
				this.DoLoad();
				this.RefreshEmptyInfo();
				return;
			}
			this.RefreshEmptyInfo();
		}
		private void newItem_Click(object sender, RoutedEventArgs e)
		{
			EmojiItem emojiItem = sender as EmojiItem;
			if (emojiItem == null)
			{
				return;
			}
			if (this.mEmojiSelectComplete != null)
			{
				this.mEmojiSelectComplete(emojiItem.Text);
				EmojiListCtrl.lastClickTime = DateTime.get_Now();
			}
			base.set_Visibility(1);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/Emoji/EmojiListCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.PageTitle = (TextBlock)base.FindName("PageTitle");
			this.emojiFliper = (ViewFlipper)base.FindName("emojiFliper");
			this.mScrollViewer = (ScrollViewer)base.FindName("mScrollViewer");
			this.EmojiList = (StackPanel)base.FindName("EmojiList");
		}
	}
}
